//
//  LBCategorySearchViewCell.m
//  AFNetworking
//
//  Created by luckyRoy on 2018/2/1.
//

#import "LBCategorySearchViewCell.h"
#import "Masonry.h"
#import "LBCategoryModel.h"
#import "UIColor+LBColor.h"

@interface LBCategorySearchViewCell ()

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation LBCategorySearchViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createAllView];
    }
    return self;
}

- (void)createAllView
{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.titleLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bgView);
        make.left.offset(5);
        make.right.offset(-5);
    }];
}

#pragma mark - setter

- (void)fac_updateUIViewByModel:(id)cellModel
{
    LBCategoryModel *theCellModel = cellModel;
    
    [self.titleLabel setText:theCellModel.name];
    if (theCellModel.isSelected) {
        self.bgView.backgroundColor = [UIColor colorWithRed:244/255.0 green:250/255.0 blue:255/255.0 alpha:1];
        self.titleLabel.textColor = [UIColor darkBlue];
        self.bgView.layer.borderColor = [UIColor blue].CGColor;
    } else {
        self.bgView.backgroundColor = [UIColor whiteColor];
        self.titleLabel.textColor = [UIColor blackColor];
        self.bgView.layer.borderColor = [UIColor darkGray].CGColor;
    }
}

#pragma mark - getter

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.layer.borderWidth = 0.5;
        _bgView.layer.cornerRadius = 4;
    }
    return _bgView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

+ (CGFloat)fac_heightForViewByModel:(id)cellModel
{
    CGFloat totalHeight = 50;
    
    return totalHeight;
}

@end
